package com.hualude.roadsign.service.impl;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.FeedbackDto;
import com.hualude.roadsign.dto.HomepageAboutDto;
import com.hualude.roadsign.repository.FeedbackRepository;
import com.hualude.roadsign.service.FeedbackService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by xu-jiaHui on 2017/4/10.
 */
@Service
public class FeedBackServiceImpl implements FeedbackService {
    @Resource
    private FeedbackRepository feedbackRepository;

    @Override
    @Transactional
    public Integer addFeedBack(FeedbackDto feedbackDto) throws Exception {
        return feedbackRepository.save(feedbackDto.toBean()).getFeedBackId();
    }

    @Override
    public DTResponseDto getFeedBack4Dt(DTRequestDto dtRequestDto) throws Exception {
        List<FeedbackDto> feedbackDtos = feedbackRepository.getFeedBack4Dt(dtRequestDto);
        Integer count = feedbackRepository.getFeedBackCount4Dt(dtRequestDto.getSearch());
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, feedbackDtos);
        return dtResponseDto;
    }

    /**
     * @Description: 获取首页"关于"展示数据
     * @Author: WYX.
     * @Date: 2018/6/8 20:15.
     */
    @Override
    public List<HomepageAboutDto> getAboutInfo(Integer infoId) throws Exception {
        return feedbackRepository.getAboutInfo(infoId);
    }

    /**
     * @Description: 更新"关于"数据
     * @Author: WYX.
     * @Date: 2018/6/9 17:10.
     */
    @Override
    @Transactional
    public Integer updataAboutInfo(Integer infoId, String aboutTele, String aboutFax, String aboutMail, String aboutWebsite) throws Exception {
        return feedbackRepository.updataAboutInfo(aboutTele, aboutFax, aboutMail, aboutWebsite);
    }
}
